<?php
defined('_JEXEC') or die('Restricted access');

defined('JB_FE') || define('JB_FE', realpath(dirname(__FILE__)));
defined('JB_FE_CONTROLLERS') || define('JB_FE_CONTROLLERS', JB_FE . '/controllers');
defined('JB_FE_VIEWS')  || define('JB_FE_VIEWS', JB_FE . '/views');
defined('JB_FE_MODELS')  || define('JB_FE_MODELS', JB_FE . '/models');
defined('JB_FE_JAM') || define('JB_FE_JAM', JB_FE . '/jam');
defined('JB_FE_TEMPLATES') || define('JB_FE_TEMPLATES', JB_FE . '/templates');

defined('JAM_COMPONENT_PREFIX') || define('JAM_COMPONENT_PREFIX', 'Jb');
defined('JAM_TEMPLATE') || define('JAM_TEMPLATE', 'default');

require_once( JB_FE_JAM . DS . 'loader.php' );
JamLoader::loadLib('controller');
JamLoader::loadLib('view');

 // view name = controller name = model name
$baseControllerName = JRequest::getCmd( 'view', 'default' );

jimport('joomla.filesystem.file');

if( JFile::exists( JB_FE_CONTROLLERS . DS . $baseControllerName . '.php' ) )
	require_once( JB_FE_CONTROLLERS . DS . $baseControllerName . '.php' );
else {
	require_once( JB_FE_CONTROLLERS . DS . 'default.php' );
	$baseControllerName = 'default';
}

$controllerName = JAM_COMPONENT_PREFIX . 'Controller' . JString::ucfirst( $baseControllerName );

if( !class_exists( $controllerName ) )
	JError::raiseError( 500, 'Class '.$controllerName.' not found!' );

$controller = new $controllerName();
$controller->execute( JRequest::getCmd( 'task', 'index' ) );
